package com.cryptape.cita_wallet.activity;

import android.content.Intent;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.widget.Toast;

import com.cryptape.cita_wallet.activity.transfer.TransferActivity;
import com.cryptape.cita_wallet.adapter.CloudMinerAdapter;
import com.cryptape.cita_wallet.bean.CloudMinerBean;
import com.cryptape.cita_wallet.constant.ConstantUtil;
import com.cryptape.cita_wallet.item.Token;
import com.cryptape.cita_wallet.service.http.TokenService;
import com.cryptape.cita_wallet.view.TitleBar;
import com.mangoworld.android.R;

import org.web3j.abi.datatypes.Type;

import java.util.ArrayList;
import java.util.List;

import rx.Subscriber;

/**
 * Created by dengming on 26/2/20.
 */

public class MinerIncomeActivity extends NBaseActivity {
    private RecyclerView recyclerView;
    private CloudMinerAdapter minerAdapter;
    private TitleBar mTitle;

    @Override
    protected int getContentLayout() {
        return R.layout.activity_miner_income;
    }

    @Override
    protected void initView() {
        recyclerView = findViewById(R.id.miner_income_recycler);
        mTitle = findViewById(R.id.title_bar);
        mTitle.setOnRightClickListener(new TitleBar.OnRightClickListener() {
            @Override
            public void onRightClick() {
                startActivity(new Intent(MinerIncomeActivity.this, MiningIndexActivity.class));
            }
        });
    }

    @Override
    protected void initData() {
        initMinerData();
    }

    @Override
    protected void initAction() {

    }

    private void initMinerData() {
        initAdapter();
        TokenService.minerDetail().subscribe(new Subscriber<List<Type>>() {
            @Override
            public void onCompleted() {

            }

            @Override
            public void onError(Throwable e) {
                Toast.makeText(MinerIncomeActivity.this, getString(R.string.network_error), Toast.LENGTH_SHORT).show();
            }

            @Override
            public void onNext(List<Type> datas) {
                if (datas != null && datas.size() > 0) {

                }
            }
        });
    }

    private void initAdapter() {
        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(mActivity);
        linearLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);
        recyclerView.setLayoutManager(linearLayoutManager);
        List<CloudMinerBean> datas = new ArrayList<>();
        datas.add(new CloudMinerBean());

        minerAdapter = new CloudMinerAdapter(this, datas);
        recyclerView.setAdapter(minerAdapter);

        minerAdapter.setOnItemClickListener((view, position) -> {
            Token token = new Token(ConstantUtil.ETH_MAINNET, ConstantUtil.HMIO_TOKEN_SYMBOL, ConstantUtil.ETHEREUM_MAIN_ID);
            Intent intent = new Intent(MinerIncomeActivity.this, MinerPayActivity.class);
            token.setContractAddress(ConstantUtil.getHToken());// "0xb2054aDd212F19581aEB195FDa7644471a996134";
            token.decimals = 18;
            intent.putExtra(TransferActivity.EXTRA_TOKEN, token);
            intent.putExtra(TransferActivity.EXTRA_ADDRESS, ConstantUtil.getMinerSellContract());
            startActivity(intent);
        });
    }
}
